package com.xj.ideatest.dialog;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.ui.content.ContentManager;
import org.jetbrains.annotations.NotNull;

import javax.swing.JComponent;

public class MyToolWindowFactory implements ToolWindowFactory, Condition<Project> {

    /**
     * 创建 tool window
     *
     * @param project    当前项目
     * @param toolWindow 当前工具窗口
     */
    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        ContentManager contentManager = toolWindow.getContentManager();
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();

        // 创建接口管理窗口
        JkglForm jkglForm = new JkglForm();
        Content jkglContent = contentFactory.createContent(jkglForm.getComponent(), "接口管理", false);
        contentManager.addContent(jkglContent);

        // 创建毒鸡汤窗口
        DjtForm djtForm = new DjtForm();
        Content djtContent = contentFactory.createContent(djtForm.getComponent(), "毒鸡汤", false);
        contentManager.addContent(djtContent);

    }


    /**
     * 控制tool window是否展示
     *
     * @param project
     * @return
     */
    @Override
    public boolean value(Project project) {
        return true;
    }
}

